#include "LPC214x.h"
#include "FreeRTOS.h"
#include "logomatic_v2.hpp"

#define isrCLEAR_TIMER_1 0xFF

void vButtonISRWrapper( void ) __attribute__ ((naked));
void vButtonHandler( void ) __attribute__ ((noinline));

void vButtonHandler( void )
{
extern bool ledflag;    
    if (ledflag) {LogomaticV2Stat(STAT0, LOGOMATIC_STAT_ON);ledflag=false;}
    else {LogomaticV2Stat(STAT0, LOGOMATIC_STAT_OFF);ledflag=true;}

    T1IR = isrCLEAR_TIMER_1;
    VICVectAddr = 0;
}
/*-----------------------------------------------------------*/

void vButtonISRWrapper( void )
{
	/* Save the context of the interrupted task. */
	portSAVE_CONTEXT();

	/* Call the handler to do the work.  This must be a separate function to
	the wrapper to ensure the correct stack frame is set up. */
	__asm volatile( "bl vButtonHandler" );

	/* Restore the context of whichever task is going to run once the interrupt
	completes. */
	portRESTORE_CONTEXT();
}